<?php

class RssBlock extends BlockInstance {
	public $CI;
	
	public function __construct()
	{
		$this->CI =& get_instance();
	}
	
	public function __call($m, $a)
	{
		global $BBX;
		
		// Get a feed url and load feed items if possible
		if (strpos($m, 'content') === false)
		{
			$content  = false;
			$feed_url = $this->get_setting($a[0]['data'], 'feed_url');
		}
		else
		{
			$content  = $a[1];
			$feed_url = $this->get_setting($a[0]['data'], 'feed_url', $content->id);
		}
		
		if ($feed_url !== false)
		{
			$feed_url = prep_url($feed_url);
			$feed	  = new SimplePie();
			$feed->set_feed_url($feed_url);
			$success = $feed->init();
			$feed->handle_content_type();
			
			$data['feed'] = $feed;
		}
		else
		{
			$data['feed'] = false;
		}
		
		// Basic view data
		$data['inst'] 	  = $a[0]['data'];
		$data['content']  = $content;
		$data['feed_url'] = $feed_url;
		
		$this->CI->load->view('blocks/rss/block', $data);
	}
	
}

?>